//index.js
//获取应用实例
var app = getApp()
var upimgurl=[]
Page({
  data: {
    tempurl:[]
  },
  //事件处理函数
  uploadcircleimg: function() {
    var _this=this
    var temurls
    var imglegth
    if(upimgurl.length>=9){
      return false;
    }
   wx.chooseImage({
      count: 9, // 默认9
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function (res) {
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        imglegth=res.tempFilePaths.length
        for(var i=0;i<imglegth;i++){
          temurls=res.tempFilePaths[i]
          if(upimgurl.length<9){
            upimgurl.push(temurls)
          }   
        }
         _this.setData({
           tempurl: upimgurl
        })
         
      }
    })
      },
    previewimage:function(){
        wx.previewImage({
    current: 'http://p3.pstatp.com/large/15a60003982aba8f1989',
    urls: [
      'http://p3.pstatp.com/list/190x124/153a0002d72a157574cb',
      'http://p1.pstatp.com/list/190x124/14d4000acfaa35aa03b2',
      'http://p3.pstatp.com/list/190x124/153a0002d72a157574cb'
    ]
  });
    },
    checkTab: function (e) {
      var that = this;
      var inputtitle = wx.getStorageSync("inputtitle");
      var userInfo = wx.getStorageSync("userInfo");
      console.log("userInfo" + userInfo);
      var inputmessge = wx.getStorageSync("inputmessge");
      var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;  
      if (!myreg.test(inputtitle) || inputtitle.length !=11) {      
       
          wx.showToast({
            title: '手机号有误',
            icon: 'succes',
            duration: 1000,
            mask: true
          })    
          return;         
       
       
      } 
      if (userInfo == null || userInfo == "") {
        wx.showModal({
          title: '提示',
          content: '您没有激活状态，请去激活',
          success: function (res) {
            if (res.confirm) {
              console.log('用户点击确定');
              wx.switchTab({
                url: '../login/login'
              })
              return;

            } else if (res.cancel) {
              console.log('用户点击取消');
              return;
            }
          }
        })
      } else {
        wx.request({
          url: "https://www.szz5.com/admin/messge",
          data: {
            youwords: inputtitle,
            contact: inputmessge,
            userCardNo: userInfo
            //  code: res.code,
            //  encryptedData: userRes.encryptedData,
            //  iv: userRes.iv
          },
          header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          method: 'POST',
          //服务端的回掉
          success: function (result) {
            console.log(JSON.stringify(result));
            wx.showModal({
              title: '提示',
              content: '提交成功，是否到首页',
              success: function (res) {
                if (res.confirm) {
                  wx.switchTab({
                    url: '../index/index'
                  });
                } else if (res.cancel) {
                  console.log('用户点击取消')
                }
              }
            })            
           

            // data.expireTime = nowDate + EXPIRETIME;
            wx.setStorageSync("userInfo", result.data);
            // userInfo = data;
          }
        })
      }
    },
    inputtitle: function (e) {
      console.log("title" + e.detail.value);
      wx.removeStorageSync("inputtitle");
      wx.setStorageSync("inputtitle", e.detail.value);
    },
    inputmessge: function (e) {
      console.log("messge" + e.detail.value);
      wx.removeStorageSync("inputmessge");
      wx.setStorageSync("inputmessge", e.detail.value);
    }

   
})